package com.piggy.logi.sys.controller;

import java.util.List;
import java.util.Arrays;

import com.piggy.common.log.annotation.LogiLog;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import com.piggy.common.log.annotation.Log;
import com.piggy.common.core.web.controller.BaseController;
import com.piggy.common.log.enums.BusinessType;
import com.piggy.logi.sys.vo.LogiCustomerBookVo;
import com.piggy.logi.sys.bo.LogiCustomerBookQueryBo;
import com.piggy.logi.sys.bo.LogiCustomerBookEditBo;
import com.piggy.logi.sys.service.ILogiCustomerBookService;
import com.piggy.common.core.utils.poi.ExcelUtil;
import com.piggy.common.core.web.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.piggy.common.core.domain.R;
import java.lang.Integer;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

/**
 * 客户收发货地址管理Controller
 *
 * @author piggy
 * @date 2023-08-16
 */
@Api(value = "客户收发货地址管理控制器", tags = {"客户收发货地址管理管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/sys/book")
public class LogiCustomerBookController extends BaseController {

    private final ILogiCustomerBookService iLogiCustomerBookService;

    /**
     * 查询客户收发货地址管理列表
     */
    @ApiOperation("查询客户收发货地址管理列表")
    //@SaCheckPermission("sys:book:list")
    @GetMapping("/list")
    public TableDataInfo<LogiCustomerBookVo> list(@Validated LogiCustomerBookQueryBo bo) {
        return iLogiCustomerBookService.queryPageList(bo);
    }

    /**
     * 导出客户收发货地址管理列表
     */
    @ApiOperation("导出客户收发货地址管理列表")
    //@SaCheckPermission("sys:book:export")
    @LogiLog(title = "客户收发货地址管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public void export(@Validated LogiCustomerBookQueryBo bo, HttpServletResponse response) throws IOException {
        List<LogiCustomerBookVo> list = iLogiCustomerBookService.queryList(bo);
        ExcelUtil<LogiCustomerBookVo> util = new ExcelUtil<LogiCustomerBookVo>(LogiCustomerBookVo.class);
        util.exportExcel(response, list, "客户收发货地址管理");
    }

    /**
     * 获取客户收发货地址管理详细信息
     */
    @ApiOperation("获取客户收发货地址管理详细信息")
    //@SaCheckPermission("sys:book:query")
    @GetMapping("/{id}")
    public R<LogiCustomerBookVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return R.ok(iLogiCustomerBookService.queryById(id));
    }

    /**
     * 新增客户收发货地址管理
     */
    @ApiOperation("新增客户收发货地址管理")
    //@SaCheckPermission("sys:book:add")
    @LogiLog(title = "客户收发货地址管理", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<Integer> add(@Validated @RequestBody LogiCustomerBookEditBo bo) {
        return R.ok(iLogiCustomerBookService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改客户收发货地址管理
     */
    @ApiOperation("修改客户收发货地址管理")
    //@SaCheckPermission("sys:book:edit")
    @LogiLog(title = "客户收发货地址管理", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<Integer> edit(@Validated @RequestBody LogiCustomerBookEditBo bo) {
        return R.ok(iLogiCustomerBookService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除客户收发货地址管理
     */
    @ApiOperation("删除客户收发货地址管理")
    //@SaCheckPermission("sys:book:remove")
    @LogiLog(title = "客户收发货地址管理" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Integer> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return R.ok(iLogiCustomerBookService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
